<?php
$tareas = Tarea::model()->activos()->de_entidad($model->id, Tarea::ENTIDAD_TIPO_CONTACTO)->ordenFechaFin()->findAll();
?>
<div class="widget red">
    <div class="widget-title">
        <h4><i class="icon-tasks"></i> Tareas</h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <a href="javascript:;" class="icon-remove"></a>
        </span>
    </div>
    <div class="widget-body">
        <?php if ($tareas): ?>
            <div style='overflow:auto'> 
                <?php
                $this->widget('ext.selgridview.BootSelGridView', array(
                    'id' => 'tarea-grid',
                    'afterAjaxUpdate' => "function(id,data){ajaxActualizarActividades();}",
                    'type' => 'striped bordered hover advance',
                    'dataProvider' => new CArrayDataProvider($tareas, array('pagination' => array('pageSize' => 5))),
                    'selectableRows' => 2,
                    'columns' => array(
                        array(
                            'header' => 'Objetivos',
                            'value' => 'CHtml::link("Ver","",array("id"=>$data->id,"onClick"=>"viewModal(\'tareas/tarea/viewObjetivos/id/".$data->id."\',function(){})"))',
                            'type' => 'raw',
                        ),
                        array(
                            'header' => 'Nombre',
                            'name' => 'nombre',
                            'value' => 'CHtml::link($data->nombre,"",array("id"=>$data->id,"onClick"=>"viewModal(\'tareas/tarea/view/id/".$data->id."\',function(){})"))',
                            'type' => 'raw',
                        ),
                        array(
                            'header' => 'Descripción',
                            'name' => 'descripcion',
                            'value' => '$data->descripcion'
                        ),
                        array(
                            'header' => 'Fecha fin',
                            'name' => 'fecha_fin',
                            'value' => '!(count($data->fecha_fin)==0)?Util::FormatDate($data->fecha_fin, "d/m/Y"):$data->fecha_fin', //'Util::FormatDate($data->fecha_fin, "d/m/Y");'
                        ),
                        array(
                            'class' => 'CButtonColumn',
                            'template' => '{llamada} {sms} {email} {update} {delete}',
                            'buttons' => array(
                                'llamada' => array(
                                    'label' => '<button class="btn btn-warning"><i class="icon-phone"></i></button>',
                                    'options' => array('title' => 'Registrar llamada'),
                                    'imageUrl' => false,
                                    'url' => '$data->contacto_id.",".$data->id',
                                    'click' => 'function() {crearLlamada($(this).attr("href")); return false;}',
                                    'visible' => '$data->accion=="LLAMADA" && $data->accion_id==null && Util::checkAccess(array("action_llamada_cargarFormularioLlamadaSaliente"))',
                                ),
                                'sms' => array(
                                    'label' => '<button class="btn btn-success"><i class="icon-comments"></i></button>',
                                    'options' => array('title' => 'Enviar SMS'),
                                    'imageUrl' => false,
                                    'url' => '$data->contacto_id.",".$data->id',
                                    'click' => 'function() {enviarSmsSolo($(this).attr("href")); return false;}',
                                    'visible' => '$data->accion=="SMS" && $data->accion_id==null && Util::checkAccess(array("action_sms_cargarFormularioSms"))',
                                ),
                                'email' => array(
                                    'label' => '<button class="btn btn-inverse"><i class="icon-envelope"></i></button>',
                                    'options' => array('title' => 'Enviar Correo Electrónico'),
                                    'imageUrl' => false,
                                    'url' => '$data->contacto_id.",".$data->id',
                                    'click' => 'function() {enviarMailSolo($(this).attr("href"),"contacto/admin"); return false;}',
                                    'visible' => '$data->accion=="EMAIL" && $data->accion_id==null && Util::checkAccess(array("action_mail_cargarFormularioMail"))',
                                ),
                                'update' => array(
                                    'label' => '<button class="btn btn-primary"><i class="icon-pencil"></i></button>',
                                    'options' => array('title' => 'Actualizar'),
                                    'url' => 'Yii::app()->createUrl("tareas/tarea/update", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_tarea_update"))'
                                ),
                                'delete' => array(
                                    'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                    'options' => array('title' => 'Eliminar'),
                                    'url' => 'Yii::app()->createUrl("tareas/tarea/delete", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_tarea_delete"))',
                                ),
                            ),
                            'htmlOptions' => array(
                                'width' => '140px'
                            )
                        ),
                    ),
                ));
                ?>
            </div>
            <br>

        <?php endif; ?>
        <?php
        $this->widget(
                'bootstrap.widgets.TbButton', array(
            'id' => 'add-tarea',
            'label' => ($tareas ? '' : '<br>') . 'Agregar Tarea',
            'encodeLabel' => false,
            'icon' => $tareas ? 'plus-sign' : 'icon-tasks',
            'htmlOptions' => array(
                'onClick' => 'js:viewModal("tareas/tarea/create/tipo_entidad/' . Tarea::ENTIDAD_TIPO_CONTACTO . '/id_entidad/' . $model->id . '",function(){'
                . 'maskAttributes();})',
                'class' => $tareas ? '' : 'empty-portlet',
            ),
                )
        );
        ?>
    </div>
</div>